package com.tuxing.draa_data.pojo.center;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;
import java.time.LocalDateTime;

import com.google.common.base.Strings;
import com.tuxing.draa_data.pojo.db.*;
import com.tuxing.draa_data.pojo.DraaTemporaryBook;
import com.tuxing.draa_data.pojo.db.Crc20220606;
import com.tuxing.draa_data.pojo.db.Elsevier20220606;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 元数据基础信息表- 图书
 * </p>
 *
 * @author yuanshihang
 * @since 2021-11-30
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class NewDcBibliographyBook implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 元数据记录号
     */
    @TableId(value = "RECORD_ID", type = IdType.ASSIGN_ID)
    private Long recordId;

    /**
     * 元数据类型
     */
    @TableField("MD_TYPE")
    private String mdType;

    /**
     * 国别
     */
    @TableField("COUNTRY_CODE")
    private String countryCode;

    /**
     * 语种
     */
    @TableField("LANG_CODE")
    private Integer langCode;

    /**
     * 题名
     */
    @TableField("TITLE")
    private String title;

    /**
     * 题名译名
     */
    @TableField("TRANS_TITLE")
    private String transTitle;

    /**
     * 其他、原期刊名称、并列题名
     */
    @TableField("ALTERNATE_TITLE")
    private String alternateTitle;

    /**
     * 责任者
     */
    @TableField("AUTHOR")
    private String author;

    /**
     * 责任者译名
     */
    @TableField("AUTHOR_EN")
    private String authorEn;

    /**
     * 出版社
     */
    @TableField("PUBLISHER")
    private String publisher;

    /**
     * 原出版社
     */
    @TableField("OLD_PUBLISHER")
    private String oldPublisher;

    /**
     * 印刷ISBN
     */
    @TableField("P_ISBN")
    private String pIsbn;

    /**
     * 电子ISBN
     */
    @TableField("O_ISBN")
    private String oIsbn;

    /**
     * ISBN10
     */
    @TableField("ISBN10")
    private String isbn10;

    /**
     * ISBN13
     */
    @TableField("ISBN13")
    private String isbn13;

    @TableField("DRAA_BID")
    private String draaBid;

    /**
     * 创建人
     */
    @TableField("CREATE_BY")
    private Integer createBy;

    /**
     * 创建时间
     */
    @TableField("CREATE_DATE")
    private LocalDateTime createDate;

    /**
     * 更新人
     */
    @TableField("UPDATE_BY")
    private Integer updateBy;

    /**
     * 更新时间
     */
    @TableField("UPDATE_DATE")
    private LocalDateTime updateDate;

    @TableField("SOURCE")
    private Integer source;

    public void createByElsevier(Elsevier20220606 els) {
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = els.getName();
        if(!Strings.isNullOrEmpty(els.getAuthor()) && els.getAuthor().length() < 500) {
            this.author = els.getAuthor();
        }
        this.publisher = els.getImprint();
        this.pIsbn = els.getIsbn();
        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void createByCrc(Crc20220606 crc) {
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = crc.getName();
        this.author = crc.getAuthor();
        this.publisher = crc.getImprint();
        this.pIsbn = crc.getEisbn();
        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void create(DraaTemporaryBook draaTemporaryBook, Integer lang) {
//        this.mdType = "DCTERMS";
        this.mdType = lang == 2 ? "USMARC" : "CNMARC";
//        this.countryCode = draaTemporaryBook.get;
        this.langCode = lang;
        this.title = draaTemporaryBook.getTitle();
        this.transTitle = draaTemporaryBook.getChineseTitle();
//        this.alternateTitle = alternateTitle;
//        this.author = author;
//        this.authorEn = authorEn;
        this.publisher = draaTemporaryBook.getPublish();
//        this.oldPublisher = oldPublisher;
        this.pIsbn = draaTemporaryBook.getPIsbn();
        this.oIsbn = draaTemporaryBook.getEIsbn();
//        this.isbn10 = draaTemporaryBook.get;
//        this.isbn13 = isbn13;
        this.draaBid = draaTemporaryBook.getErId();
    }


    public void createByBegell(Begell20220606 begell20220606) {
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = begell20220606.getName();
        this.author = begell20220606.getAuthor();
        this.pIsbn = begell20220606.getPIsbn();
        this.oIsbn = begell20220606.getEIsbn();
        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void createByIet(Iet20220601 iet) {
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = iet.getName();
        this.author = iet.getAuthor();
        this.pIsbn = iet.getPIsbn();
        this.oIsbn = iet.getEIsbn();
        this.publisher = "IET Digital Library";
        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void createByIop(Iop20220607 iop20220607){
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = iop20220607.getName();
        this.author = iop20220607.getAuthor();
        this.pIsbn = iop20220607.getPisbn();
        this.oIsbn = iop20220607.getEisbn();

        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void createByRsc(Rsc20220602 rsc20220602){
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = rsc20220602.getName();
        this.author = rsc20220602.getAuthor();
        this.pIsbn = rsc20220602.getPIsbn();
        this.oIsbn = rsc20220602.getEIsbn();
        this.publisher = "Royal Society of Chemistry Press";

        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }


    public void createByAiaa(Aiaa20220601 aiaa20220601){
        this.mdType = "USMARC";
        this.countryCode = "US";
        this.langCode = 2;
        this.title = aiaa20220601.getName();
        this.author = aiaa20220601.getAuthor();
        this.pIsbn = aiaa20220601.getPisbn();
        this.oIsbn = aiaa20220601.getEisbn();

        this.createBy = -1;
        this.createDate = LocalDateTime.now();
        this.updateBy = -1;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }

    public void createByStar(ChangxiangStar20220704 star) {
        this.mdType = "CNMARC";
        this.countryCode = "CN";
        this.langCode = 4;
        this.title = star.getTitle();
        this.author = star.getAuthor();
        this.publisher = star.getPublisher();
        this.pIsbn = star.getIsbn();
        this.createBy = -2;
        this.createDate = LocalDateTime.now();
        this.updateBy = -2;
        this.updateDate = LocalDateTime.now();
        this.source = 0;
    }
}
